package cn.yeziji.file.basic;

import cn.yzj.utils.MinioOperaUtils;
import lombok.Data;

import java.text.DecimalFormat;

/**
 * 文件进度
 *
 * @author gzkemays
 * @since 2022/5/23 10:26
 */
@Data
public class FileProcess {
  public static int UN_UPLOAD = 0;
  public static int END_UPLOAD = 1;
  public static final DecimalFormat DF = new DecimalFormat("0.00");
  String filename;
  String username;
  String createTime;
  String process;
  Integer status;
  Integer chunks;
  Integer chunk;
  String size;

  public void mathProcess(int chunk, int chunks) {
    if (chunk < chunks) {
      this.process = DF.format((double) chunk / chunks);
    } else {
      this.process = "1";
    }
  }

  public void setSize(Long size) {
    if (size > MinioOperaUtils.customerSize(1, "GB")) {
      this.size = DF.format((double) size / 1024.0D / 1024.0D / 1024.0D) + "GB";
    } else if (size > MinioOperaUtils.customerSize(1, "MB")) {
      this.size = DF.format((double) size / 1024.0D / 1024.0D) + "MB";
    } else {
      this.size =
          size > MinioOperaUtils.customerSize(1, null)
              ? DF.format((double) size / 1024.0D) + "KB"
              : size + "bytes";
    }
  }
}
